package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-07-03
 * Time: 16:03
 */

class MyThread extends Thread {//继承Thread重写run()
    @Override
    public void run() {//线程入口
        while (true) {
            System.out.println("Hello MyThread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class ThreadDemo1 {
    public static void main(String[] args) {
        Thread t = new MyThread();
        t.start();//会创建新的线程，执行run()
        //t.run();//不会创建新的线程

        while (true) {
            System.out.println("Hello main!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
